package cn.edu.sdu.sol.intake_system.repository;

import cn.edu.sdu.sol.intake_system.model.po.Will;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Optional;

@Repository
public interface WillRepository extends JpaRepository<Will, Integer> {

    @Query(value = "from Will where person.personInfPk=?1")
    List<Will> findWillListByPersonInfPk(Integer personId);

    @Query(value = "from Will where department.departmentId=?1")
    List<Will> findWillListByDepartmentId(Integer departmentId);

    @Query(value = "from Will where person.personInfPk=?1 and department.departmentId=?2")
    Optional<Will> findWillByPersonInfPkAAndDepartmentId(Integer personId, Integer departmentId);

    @Query(value = "from Will where person.personInfPk=?1 and willOrder=?2")
    Optional<Will> findWillListByPersonInfPkAndWillOrder(Integer personId, Integer willOrder);

    @Query(value = "from Will where score.isPassed = true and department.departmentId=?1")
    List<Will> findPassedWillListByDepartmentId(Integer departmentId);

    @Query(value = "from Will where department.station.stationId=?1")
    List<Will> findWillListByStationId(Integer stationId);

    @Query(value = "from Will where score.isPassed = true")
    List<Will> findAllPassed();
}
